import java.util.ArrayList;
import java.util.List;

/**
 * @author LKQ
 * @date 2022/3/3 20:06
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        char[][] board = {{'B','W','.','W','.','W','W','.'}, {'B','W','.','.','W','W','W','.'}
        ,{'W','B','.','W','W','W','W','.'}, {'B','B','W','.','W','.','.','W'}, {'B','.','B','B','B','.','B','.'},
                {'B','W','B','.','.','W','B','B'},{'.','.','.','B','W','B','.','.'},{'W','B','.','B','.','.','B','W'}};
        solution.checkMove(board, 2, 7, 'B');
    }

    public boolean checkMove(char[][] board, int rMove, int cMove, char color) {

        boolean res = false;
        // 八个方向
        int[][] dirs = {{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}};
        for (int i = 0; i < 8; i++) {
            int x = dirs[i][0], y = dirs[i][1];
            List<Integer> list = new ArrayList<>();
            // 当前颜色为1，不同为0
            list.add(1);
            int ni = x + rMove, nj = y + cMove;
            while (ni >= 0 && ni < 8 && nj >= 0 && nj < 8 && board[ni][nj] != '.') {
                if (board[ni][nj] != color) {
                    list.add(0);
                } else {
                    list.add(1);
                }
                ni += dirs[i][0];
                nj += dirs[i][1];
            }
            int size = list.size();
            if  (size < 3) {
                continue;
            }
            int j = 1;
            while (j < size && list.get(j) == 0) {
                // 距开始的1最近的1
                j++;
            }
            if (j == size) {
                // 最后一个都还是0
                continue;
            }
            if  (j +1 >=3) {
                res = true;
                break;
            }
        }
        return res;
    }
}
